*----------------
*Import the Data
*----------------
clear all
global mc "/Users/`c(username)'/Dropbox/Espacio Familiar"
global nino "$mc/Niño Rentabilidad"
import excel "$nino/Data.xlsx", clear firstrow

encode Company, generate(company)
encode Period, generate(time)
drop Company Period
rename (company time) (Company Period)
xtset Company Period // Declare the cross-sectional units and time periods

*-----------------------
*Descriptive statistics
*-----------------------
summarize Grossm Operm Ebitdam Netincomem lev rea gdp exr 
corr Grossm Operm Ebitdam Netincomem Niño niña covid19 greatrec lev gdp exr rea

*-------------------------------
*Unit Root test (Levin-Lin-Chu)
*-------------------------------
foreach var in Grossm Operm Ebitdam Netincomem lev rea gdp exr {
    xtunitroot llc `var', lags(bic 10) demean
}

*The test results indicate that all variables do not exhibit unit roots at the 1% significance level.

*----------------------------------------------------
*Dynamic Panel Approach by Arellano and Bond (1991)
*----------------------------------------------------

foreach var in Grossm Operm Ebitdam Netincomem {
    xtabond `var' l(0/1).lev l(0/1).gdp l(0/1).exr l(0/2).rea Niño niña covid19 greatrec, lags(1) vce(robust)
    xtabond `var' l(0/1).lev l(0/2).rea Niño niña covid19 greatrec, lags(1) vce(robust)
    xtabond `var' l(0/1).lev l(0/1).gdp l(0/1).exr l(0/2).rea Niño niña greatrec, lags(1) vce(robust)
    xtabond `var' l(0/1).lev l(0/1).gdp l(0/1).exr l(0/2).rea Niño niña covid19, lags(1) vce(robust)
}

*----------------------------------
*Sargan Test of the propose models
*----------------------------------
foreach var in Grossm Operm Ebitdam Netincomem {
    foreach spec in ///
        "l(0/1).lev l(0/1).gdp l(0/1).exr l(0/2).rea Niño niña covid19 greatrec" ///
        "l(0/1).lev l(0/2).rea Niño niña covid19 greatrec" ///
        "l(0/1).lev l(0/1).gdp l(0/1).exr l(0/2).rea Niño niña greatrec" ///
        "l(0/1).lev l(0/1).gdp l(0/1).exr l(0/2).rea Niño niña covid19" {
        
        quietly xtabond `var' `spec', lags(1) 
        estat sargan  // Sargan test
    }
}

*------------------------
*Serial Correlation Test
*------------------------
foreach var in Grossm Operm Ebitdam Netincomem {
    foreach spec in ///
        "l(0/1).lev l(0/1).gdp l(0/1).exr l(0/2).rea Niño niña covid19 greatrec" ///
        "l(0/1).lev l(0/2).rea Niño niña covid19 greatrec" ///
        "l(0/1).lev l(0/1).gdp l(0/1).exr l(0/2).rea Niño niña greatrec" ///
        "l(0/1).lev l(0/1).gdp l(0/1).exr l(0/2).rea Niño niña covid19" {
        
        quietly xtabond `var' `spec', lags(1) vce(robust) 
        estat abond, artest(3)  // Serial correlation test
    }
}
